
package xj.graph2d.app.diagram;

import xj.graph2d.Document;
import xj.graph2d.DrawShape;
import xj.graph2d.DrawShapeBase;
import xj.graph2d.DrawShapeConstants;
import xj.graph2d.DrawShapeFactory;
import xj.graph2d.GraphEdgeBase;
import xj.graph2d.GraphNodeBase;
import xj.graph2d.app.DrawApp;
import xj.graph2d.layout.UseCaseDiagramLayout;
import xj.graph2d.template.UMLTemplate;

public class UseCaseDiagramBuilder 
  extends DiagramBuilder { 

  public UseCaseDiagramBuilder(DrawApp main, String name) {
    super(main, name, Document.DocumentType.UML_Use_Case_Diagram);

    diagram.setGraphLayoutManager(new UseCaseDiagramLayout(diagram));    
  }

  public static GraphNodeBase makeActorShape(String name, 
					     boolean human) { 
    String tempname;
    if (human) { 
      tempname = "UMLUseCaseDiagram.Actor1"; 
    } else { 
      tempname = "UMLUseCaseDiagram.Actor2"; 
    }
    GraphNodeBase node = (GraphNodeBase) makeShape(tempname);
    if (name != null) { 
      node.setLabelString(name);
    }
    return node;     
  }

  public static GraphNodeBase makeUseCaseShape(String name) { 
    String tempname = "UMLUseCaseDiagram.UseCase"; 
    GraphNodeBase node = (GraphNodeBase) makeShape(tempname);
    if (name != null) { 
      node.setLabelString(name);
    }
    return node; 
  }

  // use case edge type 
  public static int USE_CASE_EXTENSION   = 1;
  public static int USE_CASE_DEPENDENCY  = 2;
  public static int USE_CASE_ASSOCIATION = 3;

  public static GraphEdgeBase makeUseCaseEdgeShape(int type) { 
    String tempname = "UMLUseCaseDiagram.Association"; 
    if (type == USE_CASE_EXTENSION) {
      tempname = "UMLUseCaseDiagram.Extension"; 
    } else if (type == USE_CASE_DEPENDENCY) {
      tempname = "UMLUseCaseDiagram.Dependency"; 
    }

    GraphEdgeBase edge = (GraphEdgeBase) makeShape(tempname); 
    if (type == USE_CASE_EXTENSION) {
      edge.setEdgeType(UMLTemplate.GENERALIZATION_EDGE);
    } else if (type == USE_CASE_DEPENDENCY) {
      edge.setEdgeType(UMLTemplate.DEPENDENCY_EDGE);
    } else { 
      edge.setEdgeType(UMLTemplate.ASSOCIATION_EDGE);
    }
    return edge;
  }

}